//
//  PartyServiceCenterTableViewCell.m
//  ShangHaiHuDongApp
//
//  Created by 刘应平 on 2017/6/14.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "PartyServiceCenterTableViewCell.h"

@interface PartyServiceCenterTableViewCell ()
/**  背景视图  */
@property (strong, nonatomic) UIView  *backView;
/**  图片  */
@property (strong, nonatomic) UIImageView  *lpImageView;
/**  标题  */
@property (strong, nonatomic) UILabel  *headLine;
/**  number  */
@property (strong, nonatomic) UILabel  *number;
/**  预约  */
@property (strong, nonatomic) UIButton  *yuyueButton;
/**  内容  */
@property (strong, nonatomic) UILabel  *content;


@end
/**  305 */
@implementation PartyServiceCenterTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = [UIColor themeGrayColor];
        
        [self addSubview:self.backView];
        [self.backView addSubview:self.lpImageView];
        [self.backView addSubview:self.headLine];
        [self.backView addSubview:self.number];
        [self.backView addSubview:self.content];
        [self.backView addSubview:self.yuyueButton];
        
        self.backView.sd_layout
        .topEqualToView(self)
        .bottomSpaceToView(self, 15 * [UIScreen zj_screenHScale])
        .leftSpaceToView(self, 10 * [UIScreen zj_screenWScale])
        .rightSpaceToView(self, 10 * [UIScreen zj_screenWScale]);
        
        
        self.lpImageView.sd_layout
        .topEqualToView(self.backView)
        .leftEqualToView(self.backView)
        .rightEqualToView(self.backView)
        .heightIs(200 * [UIScreen zj_screenHScale]);
        
        self.headLine.sd_layout
        .topSpaceToView(self.lpImageView, 15 * [UIScreen zj_screenHScale])
        .leftSpaceToView(self.backView, 20 * [UIScreen zj_screenWScale])
        .heightIs(15 * [UIScreen zj_screenHScale])
        .widthIs(240 * [UIScreen zj_screenWScale]);
        
        
        
        self.number.sd_layout
        .leftEqualToView(self.headLine)
        .topSpaceToView(self.headLine, 15 * [UIScreen zj_screenHScale])
        .heightIs(15 * [UIScreen zj_screenHScale])
        .widthIs([UIScreen zj_screenWith] - 60 * [UIScreen zj_screenWScale]);
        
        
        self.yuyueButton.sd_layout
        .topSpaceToView(self.headLine, 5 * [UIScreen zj_screenHScale])
        .rightSpaceToView(self.backView, 10 * [UIScreen zj_screenWScale])
        .heightIs(30 * [UIScreen zj_screenHScale])
        .widthIs(45 * [UIScreen zj_screenWScale]);
        
        TenGrayShadowView *ten = [TenGrayShadowView new];
        ten.backgroundColor = [UIColor themeGrayColor];
        [self addSubview:ten];
        ten.sd_layout
        .bottomEqualToView(self)
        .leftSpaceToView(self, 10 * [UIScreen zj_screenWScale])
        .rightSpaceToView(self, 10 * [UIScreen zj_screenWScale])
        .heightIs(15 * [UIScreen zj_screenHScale]);
        
    }
    return self;
}

- (void)clickButton{
    if (self.delegate) {
        [self.delegate PartyServiceCenterTableWithCell_index:self.row section:self.section];
    }
}

#pragma mark - getter

- (UIView *)backView{
    if (!_backView) {
        _backView = [UIView new];
        _backView.backgroundColor = [UIColor whiteColor];
    }
    return _backView;
}

- (UIImageView *)lpImageView{
    if (!_lpImageView) {
        _lpImageView = [UIImageView new];
        _lpImageView.contentMode = UIViewContentModeScaleToFill;
    }
    return _lpImageView;
}

- (UILabel *)headLine{
    if (!_headLine) {
        _headLine = ({
            UILabel *label = [UILabel new];
            label.textAlignment = NSTextAlignmentLeft;
            label.textColor = [UIColor textBlackColor];
            label.backgroundColor = [UIColor clearColor];
            label.font = LYPBOLDFONT(17);
            label;
        });
    }
    return _headLine;
}


- (UILabel *)number{
    if (!_number) {
        _number = ({
            UILabel *label = [UILabel new];
            label.textAlignment = NSTextAlignmentLeft;
            label.textColor = [UIColor lightGrayColor];
            label.backgroundColor = [UIColor clearColor];
            label.font = LYPFONT(16);
            label;
        });
    }
    return _number;
}

- (UILabel *)content{
    if (!_content) {
        _content = ({
            UILabel *label = [UILabel new];
            label.textAlignment = NSTextAlignmentLeft;
            label.numberOfLines = 0;
            label.textColor = [UIColor lightGrayColor];
            label.backgroundColor = [UIColor clearColor];
            label.font = LYPFONT(15);
            label;
        });
    }
    return _content;
}

- (UIButton *)yuyueButton{
    if (!_yuyueButton) {
        _yuyueButton = ({
            UIButton *button = [UIButton new];
            [button setTitle:@"预约" forState:UIControlStateNormal];
            [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            button.backgroundColor = [UIColor themeColor];
            [button addTarget:self action:@selector(clickButton) forControlEvents:UIControlEventTouchUpInside];
            button.layer.cornerRadius = 4;
            button.titleLabel.font = LYPFONT(16);
            button.layer.masksToBounds = YES;
            button;
            
        });
    }
    return _yuyueButton;
}

- (void)setModel:(PartyServiceCenterModel *)model{
    _model = model;
    self.headLine.text = model.NAME;
    NSString *start = [model.STARTTIME substringToIndex:5];
    NSString *end = [model.ENDTIME substringToIndex:5];
    self.number.text = [NSString stringWithFormat:@"参观时间: %@-%@",start,end];
   
    NSString *imageString;
    if (model.IMGJSON.count == 0) {
        imageString = @"meitupian";
    }else{
        imageString = [model.IMGJSON[0] objectForKey:@"FILE_PATH"];
    }
    [self.lpImageView sd_setImageWithURL:CREATEURL(imageString) placeholderImage:PlaceholderImage];
    
    
     self.content.attributedText = [UILabel setSpaceForLineWithText:model.DESCRIPTION lineSpace:5 * [UIScreen zj_screenHScale]];
    self.content.sd_layout
    .topSpaceToView(self.number, 15 * [UIScreen zj_screenHScale])
    .leftEqualToView(self.headLine)
    .widthIs([UIScreen zj_screenWith] - 60 * [UIScreen zj_screenWScale])
    .heightIs(model.HEIGHT);

}
@end
